package org.wannatrak.android;

import android.content.Context;
import org.wannatrak.android.formatter.Formatters;
import org.wannatrak.android.helper.DatabaseHelper;
import org.wannatrak.android.intf.Formatter;
import org.wannatrak.android.provider.ProjectDbOpenHelper;
import org.wannatrak.android.service.*;

/**
 * @Author: Maksim Tulupov maxtulupov@gmail.com
 * @Date: $Date: 2011-06-16 09:09:39 +0000 (Thu, 16 Jun 2011) $ 12:56 PM
 * @version: $Revision: 9 $
 * @id: $Id: ApplicationContext.java 9 2011-06-16 09:09:39Z maxtulupov@gmail.com $
 */
public class ApplicationContext {

    public static String DB_NAME = "test";

    public static double LOC_MULTIPLY = 1e6;

    public static String AUTHORITY = "org.wannatrak.android.entity";

    public static String URL = "http://www.wannatrak.com";

    private static CommonService commonService;

    private static HttpService httpService;

    private static SettingService settingService;

    private static DatabaseHelper databaseHelper;

    private static WannatrakService wannatrakService;

    private static WannatrakGPSService wannatrakGPSService;

    private static TrackCounterService trackCounterService;

    private static TrackHistoryService trackHistoryService;

    private static Formatters formatters;

    private static boolean inited;

//    private static Map<String, Object> globalParams = new ConcurrentHashMap<String, Object>();

    public static void init(Context context) {
        if (!inited) {
            commonService = new CommonService(context);
            settingService = new SettingService(context);
            httpService = new HttpService();
            databaseHelper = new DatabaseHelper(new ProjectDbOpenHelper(context));
            formatters = new Formatters(context);
            wannatrakService = new WannatrakService(context);
            wannatrakGPSService = new WannatrakGPSService(context);
            trackCounterService = new TrackCounterService(context);
            trackHistoryService = new TrackHistoryService(context);
            inited = true;
        }
    }

    public static CommonService getCommonService() {
        return commonService;
    }

    public static SettingService getSettingService() {
        return settingService;
    }

    public static HttpService getHttpService() {
        return httpService;
    }

    public static DatabaseHelper getDatabaseHelper() {
        return databaseHelper;
    }

//    public static void addParam(String key, Object value) {
//        globalParams.put(key, value);
//    }
//
//    public static Object getParam(String key) {
//        return  globalParams.get(key);
//    }
//
//    public static Object removeParam(String key) {
//        return  globalParams.remove(key);
//    }

    public static Formatter getFormatter(String key) {
        return formatters.getFormatter(key);
    }

    public static Formatter getFormatter(Class clazz) {
        return formatters.getFormatter(clazz);
    }

    public static WannatrakService getWannatrakService() {
        return wannatrakService;
    }

    public static WannatrakGPSService getWannatrakGPSService() {
        return wannatrakGPSService;
    }

    public static TrackCounterService getTrackCounterService() {
        return trackCounterService;
    }

    public static TrackHistoryService getTrackHistoryService() {
        return trackHistoryService;
    }
}
